import {defineStore} from "pinia";
import {ref, type Ref, type UnwrapRef} from 'vue'
import Article  from "../dto/Article";

export const useArticleStore = defineStore('articleStore',
()=>{
    const hotArticles:Ref<Array<Article>> = ref([])
    const defaultArticle:Ref<UnwrapRef<Article>> = ref(new Article())

    function getArticles(){
        return hotArticles
    }
    function getTopOneArticle(){
        if(hotArticles.value[0] == undefined)
            return defaultArticle.value
        return hotArticles.value[0]
    }
    function setArticles(articles:Article[]){
        hotArticles.value = hotArticles.value.concat(articles)
    }
   // async function $reset(){
   //     hotArticles.value = await microServiceHttpServer.getTopArticles()
   //  }
    return {hotArticles,setArticles ,getArticles,getTopOneArticle ,defaultArticle}
}
);